package com.example.testapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

public class FragmentActivity extends AppCompatActivity implements ListFragment.onTitleClickLister {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);

        // 视图点击事件
        findViewById(R.id.textView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 加载静态fragment
                Intent intent = new Intent(FragmentActivity.this,StaticLoadFragmentActivity.class);
                startActivity(intent);
            }
        });
        // 动态加载

        //ListFragment fragment = new ListFragment();

       // getSupportFragmentManager().beginTransaction().add(R.id.listContainer,fragment).commit();
        //getSupportFragmentManager().beginTransaction().add(R.id.detailContainer,new ListFragment()).commit();
        // 传参
        // activity ---> fragment value
        ListFragment listFragment = ListFragment.newInstance("list");
        getSupportFragmentManager().beginTransaction().add(R.id.listContainer,listFragment).commit();
        listFragment.setmOnTitleClickListener(this);

        getSupportFragmentManager().beginTransaction().add(R.id.detailContainer,ListFragment.newInstance("detail")).commit();

    }

    @Override
    public void onClick(String title) {
        setTitle(title);

    }
}
